<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="">
        <!-- 如果提交其他文本值，比如用户名、密码、性别等等，name随便写 -->
        <!-- 如果上传文件，name必须叫做 avatar -->
        <input type="file" name="avatar">
        <button>上传</button>
      </form>
      <script src="./axios.js"></script>
      <script>
        axios.defaults.baseURL = 'http://www.itcbc.com:3006'
        document.querySelector('button').addEventListener('click',function(e){
            e.preventDefault()
            // 收集表单数据
            let fd = new FormData(document.querySelector('form'))

            axios.post('/api/formdata',fd).then(({data})=>{
                console.log(data);
            })
        })
      </script>
</body>
</html>